package com.example.testapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;

import com.example.testapplication.adapter.RecyclerStaggeredAdapter;
import com.example.testapplication.bean.Goods;
import com.example.testapplication.widget.SpacesItemDecoration;

public class RecyclerStaggeredActivityI extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_staggered3);
        initRecyclerStaggered();
    }

    private void initRecyclerStaggered() {
        RecyclerView rv_staggered = findViewById(R.id.rv_staggered);
        StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(3,RecyclerView.VERTICAL);
        rv_staggered.setLayoutManager(manager);
        RecyclerStaggeredAdapter adapter = new RecyclerStaggeredAdapter(this, Goods.getDefaultStag());
        adapter.setOnItemClickListener(adapter);
        adapter.setOnItemLongClickListener(adapter);
        rv_staggered.setAdapter(adapter);
        rv_staggered.setItemAnimator(new DefaultItemAnimator());
        rv_staggered.addItemDecoration(new SpacesItemDecoration(1));
    }
}